<?php
namespace app\common\controller;

use think\Controller;
use think\Request;

class Common extends Controller
{
	protected $param;
	
	public function initialize()
	{
		parent::initialize();
		// header('Access-Control-Allow-Origin: '.$_SERVER['HTTP_ORIGIN']);
		header('Access-Control-Allow-Origin:*');
		header('Access-Control-Allow-Credentials: true');
		header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
		header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, authKey");
		if ($this->request->isOptions())
			exit();
		$this->param = $this->request->param();
	}
	
    /**
     * a tool function to simplify param value in the request.
     * 
     * @param string the param name you want
     * @param any $default the default value when the param name cannot be found.
     * 
     * @return any
     */
	
	public function param($name,$default=null){
		$param=$this->param;
		return isset($param[$name])?$param[$name]:$default;
	}
}
